package jianzhiOffer;

public class Num63 {
    public int maxProfit(int[] prices) {
        if(prices.length == 0) return 0;
        int minmoney = prices[0];
        int maxmoney = 0;
        for(int i = 1; i < prices.length; i++) {
            if(prices[i] < minmoney) {
                minmoney = prices[i];
                continue;
            }
            if(prices[i] > minmoney) {
                maxmoney = Math.max(maxmoney,prices[i] - minmoney);
            }
        }
        return maxmoney;
    }
}
